package com.mrx.spring.example.runner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;

/**
 * @author Mr.X
 * @since 2023-11-28 11:48
 **/
@Component
public class FeignTracerRunner {

    @Resource
    private FeignTracerTest feignTracerTest;

    private static final Logger logger = LoggerFactory.getLogger(FeignTracerRunner.class);

    @Async("traceExecutor")
    @EventListener(ApplicationReadyEvent.class)
    public void init() {
        try {
            logger.debug("test: {}", feignTracerTest.get());
        } catch (Exception e) {
            logger.error("出现异常: ", e);
        }
    }

    @FeignClient(name = "testService", url = "https://baidu.com")
    public interface FeignTracerTest {

        @GetMapping("/get")
        String get();

    }

}
